package com.newsystem.controller;


import com.newsystem.MyUtils.CommonResult;
import com.newsystem.mapper.CommentMapper;
import com.newsystem.pojo.Comment;
import com.newsystem.service.impl.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 评论表 前端控制器
 * </p>
 *
 * @author chenlitao
 * @since 2022-11-06
 */
@RestController
@RequestMapping("/comment")
@RequiredArgsConstructor
public class CommentController {

    private final CommentMapper commentMapper;
    private final CommentService commentService;

    @ApiOperation("用户添加评论")
    @PostMapping("/addComment")
    public CommonResult<Object> addComment(String userId,String newsId,String content){
        return commentService.instertComment(userId,newsId,content);
    }

    @ApiOperation("用户修改评论")
    @PostMapping("/updateComment")
    public CommonResult<Object> updateComment(String userId,String commemtId,String content){
        return commentService.updateComment(userId,commemtId,content);
    }

    //todo
    @ApiOperation("用户删除评论")
    @DeleteMapping("/deleteComment")
    public CommonResult<Object> deleteComment(String userId,String commentId){
        return commentService.deleteComment(userId,commentId);
    }


    @ApiOperation("用户获得相关新闻的评论内容列表")
    @GetMapping("/getCommentList")
    public CommonResult<Object> getCommentList(String newsId){
        return commentService.selectCommentList(newsId);
    }


    @ApiOperation("根据评论id获得评论内容")
    @GetMapping("/getComment")
    public CommonResult<Object> getComment(String commonId){
        Comment comment = commentMapper.selectById(commonId);
        if(comment!=null){
            return CommonResult.success(comment);
        }
        return CommonResult.failed("查无评论");
    }



}

